package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**集合排序 --String--*/
public class SortString {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("F");
        list.add("a");
        list.add("fa");
        list.add("f");
        list.add("l");
        list.add("Z");
        System.out.println(list);
        Collections.sort(list);//排序按照ASCII码号进行排序
        System.out.println("排序后:"+list);

        List<String> list1 = new ArrayList<>();
        list1.add("李云飞aa");
        list1.add("飞云李");
        list1.add("云李飞aaa");
        Collections.sort(list1, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();//升序
                //return o2.length()-o1.length();//降序
            }
        });
        System.out.println(list1);
    }
}
